﻿using Coldairarrow.Business.PB;
using Coldairarrow.Entity.DTO;
using Coldairarrow.Entity.PB;
using Coldairarrow.Util;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Coldairarrow.Api.Controllers.PB
{
    [Route("/PB/[controller]/[action]")]
    public class PB_PrinterController : BaseApiController
    {
        #region DI

        public PB_PrinterController(IPB_PrinterBusiness pB_PrinterBus)
        {
            _pB_PrinterBus = pB_PrinterBus;
        }

        IPB_PrinterBusiness _pB_PrinterBus { get; }

        #endregion

        #region 获取

        [HttpPost]
        public async Task<PageResult<PB_PrinterDTO>> GetDataList(PageInput<ConditionDTO> input)
        {
            return await _pB_PrinterBus.GetDataListAsync(input);
        }

        /*
         * 创建人：崔楠
         * 创建时间：2020-03-18 10:59
         * 描述：打印服务获取打印机列表，不需要token
         */
        /// <summary>
        /// 打印服务获取打印机列表
        /// </summary>
        /// <param name="deptId">部门ID</param>
        /// <returns></returns>
        [HttpPost]
        [NoCheckJWT]
        public async Task<List<PB_PrinterSelectDTO>> GetDataListByPrintService(string deptId)
        {
            return await _pB_PrinterBus.GetDataListByPrintServiceAsync(deptId);
        }

        [HttpPost]
        public async Task<PB_Printer> GetTheData(IdInputDTO input)
        {
            return await _pB_PrinterBus.GetTheDataAsync(input.id);
        }

        #endregion

        #region 提交

        [HttpPost]
        public async Task SaveData(PB_Printer data)
        {
            if (data.Id.IsNullOrEmpty())
            {
                InitEntity(data);

                await _pB_PrinterBus.AddDataAsync(data);
            }
            else
            {
                await _pB_PrinterBus.UpdateDataAsync(data);
            }
        }

        [HttpPost]
        public async Task DeleteData(List<string> ids)
        {
            await _pB_PrinterBus.DeleteDataAsync(ids);
        }

        #endregion
    }
}